<template>
  <div style="position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 400px;">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">登入</el-button>
        <el-button>注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import request from "@/util/request";

export default {
  name: "Login",
  data() {
    return {
      form: {
        name: '',
        password: '',
      }
    }
  },
  methods: {
    onSubmit() {
      request.post('/api/loginCheck2',this.form).then(res => {


        // console.log(res)
        if (res.code === 200) {

          localStorage.setItem('token',res.data);
          this.$message({
            type: "success",
            message: "成功"
          })
          this.$router.push('/home/homeView')
        } else if (res.code === 501) {
          this.$message({
            type: "error",
            message: res.msg
          })
        } else if (res.code === 502) {
          this.$message({
            type: "error",
            message: res.msg
          })
        }else {
          this.$message({
            type: "error",
            message: res.msg
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>